package com.time.workbench.core.config;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.time.workbench.core.util.AuthUtil;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;

import java.util.List;

public class StoreTenantLineHandler implements TenantLineHandler {
    // 多租户忽略表
    private final List<String> tenantLineIgnoreTables = CollectionUtil.newArrayList(
            "system_garbage",
            "system_dict",
            "system_dict_type",
            "logging_event",
            "logging_event_property"
    );

    @Override
    public Expression getTenantId() {
        Integer currUserTenantId = AuthUtil.getCurrTenantId();
        return new LongValue(currUserTenantId);
    }

    @Override
    public boolean ignoreTable(String tableName) {
        if (tenantLineIgnoreTables.contains(tableName))
            return true;
        return false;
    }

    @Override
    public String getTenantIdColumn() {
        return "tenant_id";
    }
}
